package com.yunzo.coc.api;

import com.jfinal.core.Controller;
import com.yunzo.coc.common.bean.DataResponse;
import com.yunzo.coc.common.Require;
import com.yunzo.coc.common.utils.JsonObjectUtil;
import com.yunzo.coc.common.utils.RandomUtils;
import com.yunzo.coc.common.utils.StringUtils;
import com.yunzo.coc.model.GroupBusinessinfoModel;
import com.yunzo.coc.model.GroupMemberCompanyModel;
import com.yunzo.coc.model.GroupMemberModel;
import com.yunzo.coc.model.GroupMemberinfoModel;
import com.yunzo.coc.model.SystemCollectModel;
import com.yunzo.coc.common.bean.BaseResponse;
import com.yunzo.coc.common.bean.Code;
import com.yunzo.coc.common.bean.coc.GroupMemberInfoEntey;
import com.yunzo.coc.common.bean.param.Feedback;
import com.yunzo.coc.common.token.TokenManager;

import java.io.BufferedReader;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.List;

/**
 * 基本的api
 * 基于jfinal controller做一些封装
 * @author xiaobo
 */
public class BaseAPIController extends Controller {

	//短信验证码
	/**
	 * 短信验证码 参数 手机号码 和验证码
	 */
	public static final String SMSAUTHCODESQL = "SELECT * FROM y_basic_smsauthcode WHERE usertell=? AND authcode = ?";
	
	public static final String QUERY_GROUPINFO="SELECT ids,orderids,gname FROM y_group_info where 1=1 and gisopenstrategy=0 and status=0 order by orderids ASC";
	/**
	 * 短信验证码 参数 手机号码 
	 */
	public static final String SMSAUTHCODEUSERSQL = "SELECT * FROM y_basic_smsauthcode WHERE usertell=? limit 1";
	/**
	 * 删除短信验证码 参数 手机号码 和验证码
	 */
	public static final String DELSMSAUTHCODESQL = "DELETE FROM y_basic_smsauthcode WHERE usertell=? AND authcode = ?";
	/**
	 * 删除短信验证码 参数 手机号码 和验证码
	 */
	public static final String UPDSMSAUTHCODESQL = "UPDATE  y_basic_smsauthcode SET authcode = ? WHERE usertell=? ";
	
	/**
	 * 获取点赞总数
	 */
	public static final String GET_POINTLIKE_SUMNUMBER_SQL = " SELECT count(*) as scount FROM y_system_pointlike WHERE groupid=? AND pointliketype = ? AND pointlikeid=?";
	/**
	 * 删除点赞的数据
	 */
	public static final String DEL_POINTLIKE_SQL = "DELETE FROM  y_system_pointlike WHERE groupid=? AND pointliketype = ? AND pointlikeid=? AND mids=?";
	/**
	 * 删除关注的数据
	 */
	public static final String DEL_CONNECT_SQL = "DELETE FROM  y_group_member_concern WHERE groupid=? AND dids=? AND concomments=? AND frommid=? and tomid=?";
	/**
	 * 删除收藏的数据
	 */
	public static final String DEL_COLLECT_SQL = "DELETE FROM  y_system_collect WHERE groupid=? AND mids=? AND collecttype=? AND collectid=?";
	/**
	 * 获取会员是否点赞操作
	 */
	public static final String GET_POINTLIKE_ISOPEN_SQL = " SELECT * FROM y_system_pointlike WHERE groupid=? AND pointliketype = ? AND pointlikeid=? AND mids=?";
	
	/**
	 * 获取评论总数
	 */
	public static final String GET_REVIEW_SUMNUMBER_SQL = " SELECT count(*) as scount FROM y_system_review WHERE groupid=? AND reviewtype = ? AND reviewid=?";

	/**
	 * 获取评论回复总数
	 */
	public static final String GET_REVIEW_REP_SUMNUMBER_SQL = " SELECT count(*) as scount FROM y_system_review_reply WHERE reviewid=?";
	/**
	 * 取得参加通知的总人数
	 */
	public static final String GROUPINFORMINFO_SUMNUMBER_SQL="SELECT count(*) as scount FROM y_group_inform_join WHERE groupid=?  AND infoids=? AND state=0";
	/**
	 * 取得会员是否参加 通知状态
	 */
	public static final String GROUPINFORMINFO_ISJOIN_SQL="SELECT * FROM y_group_inform_join WHERE groupid=?  AND infoids=? AND state=0 AND mids=?";
	
	/**
	 * 删除会员参加通知信息
	 */
	public static final String DEL_GROUPINFORMINFO_SQL = "DELETE FROM  y_group_inform_join WHERE groupid=? AND infoids = ? AND  state=0  AND mids=?";
	/**
	 * 取得商机浏览的总人数
	 */
	public static final String GROUPBUSINESSINFOBROWSE_SUMNUMBER_SQL="SELECT count(*) as scount FROM y_group_businessinfo_browse WHERE biids=?";
	/**
	 * 取得通知浏览的总人数
	 */
	public static final String GROUPINFOFORMBROWSE_SUMNUMBER_SQL="SELECT count(*) as scount FROM y_group_inform_browse WHERE ginfoids=?";
	/**
	 * 取得炫浏览的总人数
	 */
	public static final String GROUPMSHOWBROWSE_SUMNUMBER_SQL="SELECT count(*) as scount FROM y_group_member_showtime_browse WHERE mshowids=?";
	
	/**
	 * 取得收藏的总数
	 */
	public static final String SYSTEMCOLLECT_SUMNUMBER_SQL="SELECT count(*) as scount FROM y_system_collect WHERE  collecttype=? AND collectid=?";
	/**
	 * 取得会员是否有收藏这条信息
	 */
	public static final String SYSTEMCOLLECT_ISCOLL_SQL="SELECT * FROM y_system_collect WHERE groupid=? AND collecttype=? AND collectid=? AND mids=?";
	/**
	 * 取得关注的总数
	 */
	public static final String MEMBERCONCERN_SUMNUMBER_SQL="SELECT count(*) as scount FROM y_group_member_concern WHERE groupid=? AND dids=? AND concomments=?";
	/**
	 * 取得会员是否有关注过这条信息
	 */
	public static final String MEMBERCONCERN_ISCONCERN_SQL="SELECT * FROM y_group_member_concern WHERE groupid=? AND dids=? AND concomments=? AND frommid=?";
	
	//会员
	/**
	 * 会员基础信息 参数 手机号码  
	 */
	public static final String MEMBERMIDSSQL = "SELECT * FROM y_group_member WHERE 1=1 and mids=?";
	
	/**
	 * 会员基础信息 参数 手机号码  
	 */
	public static final String MEMBERMIDSSQL_GROUP = "SELECT * FROM y_group_member WHERE 1=1 and mids=? and  FIND_IN_SET(?,groupids)";
	/**
	 * 会员基础信息 参数 手机号码 和密码 
	 */
	public static final String MEMBERMIDANDPWDSQL = "SELECT * FROM y_group_member WHERE mids=? AND pwd=?";
	/**
	 * 会员详细信息 参数 手机号码  
	 */
	public static final String MEMBERINFOMIDSSQL = "SELECT * FROM y_group_memberinfo WHERE 1=1 and  mids=?";
	/**
	 * 会员详细信息 参数 手机号码  
	 */
	public static final String MEMBERINFOMIDSSQLCONT = "SELECT ids,realname,mheadimage,mids FROM y_group_memberinfo WHERE 1=1 and  mids=?";
	
	/**
	 * 会员详细信息 参数 手机号码  
	 */
	public static final String MEMBERINFO_MIDANDLIKEVALUE_SSQL = "SELECT * FROM y_group_memberinfo WHERE mids=? AND find_in_set(?, realname)";

	//团体
	/**
	 * 通过ID查询团体信息
	 */
	public static final String GROUPINFOBYIDSQL="SELECT * FROM y_group_info WHERE ids=?";
	/**
	 * 查询所有团体信息 按分页大小查询列表
	 */
	public static final String GROUPALLINFOBYIDSQL="SELECT * FROM y_group_info  LIMIT ?";
	
	/**
	 * 通过团体ID和会员电话查询团体职位
	 */
	public static final String GROUPCONTACTSBYGROUPIDANDMIDSSQL="SELECT * FROM y_group_contacts WHERE groupid=? and  find_in_set(?, mids)";
	
	/**
	 * 通过团体ID和分页大小查询动态信息集合
	 */
	public static final String GROUPDYNAMICINFOLISTSQL="SELECT * FROM y_group_dynamicinfo WHERE groupid=? order by createtime  DESC LIMIT ?";
	/**
	 * 通过团体ID和分页大小查询通知信息集合 
	 */
	public static final String GROUPINFORMINFOLISTSQL="SELECT * FROM y_group_informinfo WHERE groupid=?  order by createtime  DESC LIMIT ?";
	
	/**
	 * 查询团体通知浏览信息
	 */
	public static final String GINFOMEMBERBIBROWSE_ALL_SQL="SELECT distinct mids FROM y_group_inform_browse WHERE 1=1 AND ginfoids=? order by createtime  DESC ";
	/**
	 * 查询团体炫浏览信息
	 */
	public static final String GSHOWMEMBERBIBROWSE_ALL_SQL="SELECT distinct mids FROM y_group_member_showtime_browse WHERE 1=1 AND mshowids=? order by createtime  DESC ";
	//系统
	/**
	 * 通过业务ID和类型查询评论列表 
	 */
	public static final String SYSTEMREVIEWPIDDIDSIZESQL ="SELECT * FROM y_system_review WHERE reviewid=? AND reviewtype=? order by createtime  DESC  LIMIT ?";
	/**
	 * 通过业务ID和类型查询回复列表 
	 */
	public static final String SYSTEMREVIEWREPLERIDSQL="SELECT * FROM y_system_review_reply WHERE reviewid=? order by createtime  DESC  LIMIT ?";
	
	/**
	 * 通过会员手机号码查询关注信息 
	 */
	public static final String SYSTEMCONCERNBYMIDSQL="SELECT * FROM y_group_member_concern WHERE frommid=? AND dids=? order by createtime  DESC LIMIT ?";
	/**
	 * 通过会员手机号码查询收藏内容
	 */
	public static final String SYSTEMCOLLECTBYMIDANDDIDSQL="SELECT * FROM y_system_collect WHERE mids=? AND collecttype=?  and groupid=? order by createtime  DESC LIMIT ?";
	/**
	 * 通过会员手机号码和关键字查询收藏集合
	 */
	public static final String SYSTEMCOLLECT_MIDDIDLIKE_SQL="SELECT * FROM y_system_collect WHERE mids=? AND collecttype=?  AND  find_in_set(?, collectcomment) order by createtime  DESC LIMIT ?";
	/**
	 * 通过团体ID和广告ID查询广告投放信息
	 */
	public static final String SYSTEMADINFOBYGIDANDAIDSQL="SELECT * FROM y_system_adinfo WHERE 1=1 and groupids=? AND ids=?";
	
	/**
	 * 通过广告投放类型查询广告图片
	 */
	public static final String SYSTEMADINFOBYTYPESQL="SELECT * FROM y_system_adinfo WHERE 1=1 and gadtype=? and groupids=? order by gadtype,orderids ";
	
	/**
	 * 通过团体ID,会员手机号码和关注时间查询被关注人最新一条炫标题
	 */
	public static final String MEMBERSHOWTIMEFORGROUPIDANDMIDSANDCREATETIMESQL="SELECT * FROM y_group_member_showtime WHERE groupid=? AND mids=?  order by createtime  DESC limit 1";
	
	/**
	 * 通过团体ID查询通讯录最大版本号
	 */
	public static final String GROUPINFO_MAX_VERSION_SQL="SELECT version FROM y_group_info WHERE groupid=?";
	/**
	 * 通过团体ID查询通讯录最大版本号
	 */
	public static final String GROUPCONTACTS_MAX_VERSION_SQL="SELECT * FROM y_group_contacts WHERE groupid=?  order by version limit 1";
	/**
	 * 通过团体ID查询通讯录集合
	 */
	public static final String GROUPCONTACTS_INFOLIST_SQL="SELECT * FROM y_group_contacts WHERE 1=1 and groupid=?  AND status = 0 order by orderids ASC";
	
	public static final String GROUPCONTACTS_PART_INFOLIST_SQL="SELECT ids,cnames,mids FROM y_group_contacts WHERE 1=1 and groupid=?  AND status = 0 and ISNULL(parentids)  order by orderids ASC";
	
	public static final String GROUPCONTACTS_ALLCHILD_INFOLIST_SQL="SELECT * FROM y_group_contacts WHERE 1=1 and groupid=?  AND status = 0 and !ISNULL(parentids)  order by orderids ASC";
	
	public static final String GROUPCONTACTS_PART_CHILD_INFOLIST_SQL="SELECT * FROM y_group_contacts WHERE 1=1 and groupid=?  AND status = 0 and parentids=?  order by orderids ASC";
	
	public static final String GROUPCONTACTS_ISOPENLIST_SQL="SELECT * FROM y_group_contacts WHERE 1=1 and groupid=?  AND status = 0  AND isopen = '1' order by orderids ASC";
	
	public static final String GROUPCONTATS_ALL_SQL="SELECT * FROM (SELECT m.ids,m.mheadimage, m.realname,m.nikename,m.mids,m.mnativeplace,m.msex,m.mbirthday,m.orderids,ygc.cnames,ygc.orderids as ygcorder,ygc.version as ygcversion,ygc.parentname as ygcparentname from y_group_member s  right JOIN y_group_memberinfo  m  ON m.mids = s.mids INNER  JOIN y_group_contacts ygc ON find_in_set(m.mids,ygc.mids) where 1=1 AND s.status = 0 and FIND_IN_SET(?,s.groupids) and ygc.groupid=? order BY ygcorder asc ) member LIMIT ?,?";
	/**
	 * 通过团体ID和搜索关键字查询通讯录集合
	 */
	public static final String GROUPCONTACTS_INFOLIST_QUERY_SQL="SELECT * FROM y_group_contacts WHERE groupid=?   order by version limit ?";
	
	/**
	 * 通过会员手机号码查询职务
	 */
	public static final String GROUPCONTACTS_MID_QUERY_SQL="SELECT * FROM y_group_contacts WHERE find_in_set(?, mids)";
	
	/**
	 * 通过会员手机号码和团体ID查询团体下公司信息
	 */
	public static final String MEMBER_COMPAYINGO_SQL="SELECT * FROM y_group_member_company WHERE mids=? AND groupid=?";
	
	/**
	 * 通过会员手机号码和团体ID查询团体下公司信息
	 */
	public static final String MEMBER_COMPAYINGO_COUNT_SQL="SELECT comname FROM y_group_member_company WHERE mids=? AND groupid=?";
	/**
	 * 通过会员手机号码所有公司信息
	 */
	public static final String MEMBER_COMPAYINGO_MID_SQL="SELECT * FROM y_group_member_company WHERE 1=1 and mids=?";
	/**
	 * 通过会团体ID和姓名关键字搜索会员信息
	 */
	public static final String MEMBER_CONTACTS_REALNAME="SELECT * FROM (SELECT m.ids,m.mheadimage, m.realname,m.nikename,m.mids,m.mnativeplace,m.msex,m.mbirthday,m.orderids from y_group_member s  right JOIN y_group_memberinfo  m  ON m.mids = s.mids where 1=1 AND s.status = 0 AND s.groupids =? AND  find_in_set(?, m.realname)) member";
  
	/**
	 * 通过团体ID和会员手机号码查询会员发布商机集合
	 */
	public static final String MEMBERBI_GROUPIDANDMID_SQL="SELECT * FROM y_group_businessinfo WHERE 1=1 AND status = 0  AND groupid=?  AND mids=?  order by createtime DESC limit ?";
	
	/**
	 * 通过团体ID查询团体商机集合 top5
	 */
	public static final String MEMBERBI_GROUPID_TOP5_SQL="SELECT * FROM y_group_businessinfo WHERE 1=1 AND status = 0  AND groupid=?  order by orderids limit 5";
	
	public static final String MEMBERBI_ALL_TOP5_SQL="SELECT * FROM y_group_businessinfo WHERE 1=1 AND status = 0  AND isopen=0  order by orderids limit 5";
	
	public static final String MEMBERBI_GROUPID_LIST_SQL="SELECT * FROM y_group_businessinfo WHERE 1=1 AND status = 0  AND groupid=?  order by createtime DESC limit ?,?";
	
	/**
	 * 通过团体ID查询团体商机集合
	 */
	public static final String MEMBERBI_TRADEANDLIKEVALUE_SQL="SELECT * FROM y_group_businessinfo WHERE 1=1 AND status = 0  AND groupid=? AND  find_in_set(?, bititle)  AND bicontacttrade=? order by orderids limit ?";
	
	/**
	 * 查询会部有效的团体商机集合
	 */
	public static final String MEMBERBI_ALL_SQL="SELECT * FROM y_group_businessinfo WHERE 1=1 AND status = 0 AND isopen=0 order by orderids limit ?";
	
	/**
	 * 查询团体商机浏览信息
	 */
	public static final String MEMBERBIBROWSE_ALL_SQL="SELECT distinct mids,mheadimage FROM y_group_businessinfo_browse WHERE 1=1 AND biids=? order by createtime  DESC ";
	
	/**
	 * 查询团体商机浏览信息
	 */
	public static final String MEMBERBI_ORDERIDS_SQL="SELECT orderids FROM y_group_businessinfo WHERE 1=1 AND status = 0  AND groupid=?  order by orderids DESC  limit 1 ";
	
	/**
	 * 查询行业最大版本号
	 */
	public static final String TRADE_MAX_VERSION_SQL="SELECT * FROM y_basic_trade  order by orderids limit 1";
	/**
	 * 查询行业集合
	 */
	public static final String TRADE_LIST_SQL="SELECT * FROM y_basic_trade order by orderids limit ?";
	
	/**
	 * 查询行业集合
	 */
	public static final String MEMBER_TRADE_LIST_SQL="SELECT * FROM y_group_member_label WHERE groupid=? AND mids=? AND dictname=?";
	
	/**
	 * 查询团体电商信息集合
	 */
	public static final String GROUPECINFO_LIST_SQL="SELECT * FROM y_group_ecprodinfo WHERE 1=1 and  ectypeid=?  AND status=0  order by orderids DESC limit ?";

	/**
	 * 查询团体电商分类集合
	 */
	public static final String GROUPECTYPE_LIST_SQL="SELECT * FROM y_group_ecprodtypeinfo WHERE groupid=?  AND status=0  order by orderids   limit ?";
	/**
	 * 查询全国电商分类集合
	 */
	public static final String GROUPECTYPE_ALLLIST_SQL="SELECT * FROM y_group_ecprodtypeinfo WHERE status=0 AND isoutlook=0  order by orderids   limit ?";
	
	/**
	 * 查询会员收货信息集合
	 */
	public static final String MEMBERADDRESS_LIST_SQL="SELECT * FROM y_group_member_caddress WHERE groupid=?  AND  mids=? order by orderids DESC  limit ?";
	/**
	 * 查询团体会员炫信息列表
	 */
	public static final String MEMBERSHOWTIME_GROUPID_SQL="SELECT * FROM y_group_member_showtime WHERE 1=1  AND groupid=?  order by createtime  DESC  limit ?,? ";
	
	public static final String MEMBERSHOWTIME_GROUPIDANDMID_SQL="SELECT * FROM y_group_member_showtime WHERE 1=1  AND groupid=? AND mids=?  order by createtime   DESC limit ?";
	
	/**
	 * 查询团体会员炫最大排序号对象信息
	 */
	public static final String MEMBERSHOWTIME_MAX_ORDERIDS_SQL="SELECT * FROM y_group_member_showtime WHERE 1=1  AND groupid=?  order by orderids limit 1 ";
	
	/**
	 * 查询团体APP信息
	 */
	public static final String GROUPAPP_INFO_SQL="SELECT * FROM y_group_appinfo WHERE 1=1  AND groupid=? ";
	
	/**
	 * 查询TOP5团体信息
	 */
	public static final String GROUPINFO_TOP5_SQL="SELECT * FROM y_group_info WHERE 1=1 AND status=0 AND gisopenstrategy=0  order by orderids limit 5";
	
	/**
	 * 查询TOP5全国团体商机信息
	 */
	public static final String GROUPBI_TOP5_SQL="SELECT * FROM y_group_businessinfo WHERE 1=1 AND status=0 AND isopen=0 order by orderids limit 5";
	
	/**
	 * 查询TOP5全国团体电商信息
	 */
	public static final String GROUPEC_TOP5_SQL="SELECT * FROM y_group_ecprodinfo WHERE 1=1 AND status=0 AND isoutlook=0 order by orderids limit 5";
	
	/**
	 * 根据地域和关键字查询全部团体信息
	 */
	public static final String GROUPINFO_AREAANDLIKE_SQL="SELECT * FROM y_group_info WHERE 1=1 AND status=0 AND gisopenstrategy=0  AND   AND gname LIKE '%?%' order by orderids limit ?,?";
	
	/**
	 * 根据地域查询全部团体信息
	 */
	public static final String GROUPINFO_AREA_SQL="SELECT * FROM y_group_info WHERE 1=1 AND status=0 AND gisopenstrategy=0  AND find_in_set(?, gaddress)   order by orderids limit ?";
	/**
	 * 根据关键字查询全部团体信息
	 */
	public static final String GROUPINFO_LIKE_SQL="SELECT * FROM y_group_info WHERE 1=1 AND status=0 AND gisopenstrategy=0  AND  find_in_set(?, gname)  order by orderids limit ?";
	/**
	 * 查询全部团体信息
	 */
	public static final String GROUPINFO_ALL_SQL="SELECT * FROM y_group_info WHERE 1=1 AND status=0 AND gisopenstrategy=0 order by orderids limit ?,?";
	
	/**
	 * 查询团体会员被
	 */
	public static final String GROUPMEMBERREVIEW_LIST_SQL="SELECT * FROM y_system_review WHERE groupid=? AND mids=? LIMIT ?";
	/**
	 * 查询会员的to my 私信列表
	 */
	public static final String GROUPMEMBER_INBOX_LIST_SQL="SELECT * FROM y_group_member_inbox where groupid=? and tomid=? and inboxtype=? order by createtime  DESC LIMIT ?,?";
	/**
	 * 查询会员的to my 私信列表
	 */
	public static final String GROUPMEMBER_SEND_INBOX_LIST_SQL="SELECT * FROM y_group_member_inbox where groupid=? and sendmid=? and inboxtype=? order by createtime  DESC LIMIT ?,?";
	
	public static final String GROUPMEMBER_INBOX_TOM_LIST_SQL="SELECT * FROM y_group_member_inbox where groupid=? and tomid=? and sendmid=? and inboxtype=? order by createtime  DESC LIMIT ?,?";
	/**
	 * 查询会员的私信回复列表
	 */
	public static final String GROUPMEMBER_REPLY_INBOX_LIST_SQL="SELECT * FROM y_group_member_inbox_reply where inboxid=? order by createtime  DESC";
	/**
	 * 查询会员的订单列表
	 */
	public static final String GROUPMEMBER_ORDER_LIST_SQL="SELECT * FROM y_group_ecprod_order where 1=1 and groupid=? and mids=? and status=? order by createtime  DESC LIMIT ?";
	
	
	/**
	 * 查询会员的好友信息
	 */
	public static final String GROUPMEMBER_FRIENDS_SQL="SELECT * FROM y_group_member_friends where 1=1 and groupids=? and mids=? ";
	
	/**
	 * 查询会员的好友信息是否存在相同的
	 */
	public static final String GROUPMEMBER_FRIENDS_ASSAME_SQL="SELECT * FROM y_group_member_friends where 1=1 and groupids=? and mids=? and find_in_set(?, friendsmids) ";
	/**
	 * 查询会员好友信息
	 */
	public static final String GROUPMEMBER_FRIENDS_INFO_SQL= "SELECT yg.ids,yg.mids,yg.realname,yg.headimage,ygmc.comname as comname from y_group_member yg LEFT JOIN y_group_member_company ygmc ON yg.mids=ygmc.mids where 1=1 and yg.mids=?";
	/**
	 * 查询会员的好友信息是否存在相同的
	 */
	public static final String GROUPMEMBER_FRIENDS_SMSLIST_SQL="SELECT * FROM y_group_member_friends_sms where 1=1 and  tomids=? and smsflag=? order by createtime  DESC LIMIT ?,?";
	
	public static final String GROUPMEMBER_FRIENDS_BYMIDS="SELECT * FROM y_group_member_friends where 1=1 and groupids=? and mids=?";
	
	/**
     * 获取当前用户对象
     * @return
     */
    protected GroupMemberModel getUser() {
    	GroupMemberModel user = getAttr("user");
        if (user == null) {
            String token = getPara("token");
            return StringUtils.isEmpty(token) ? null : TokenManager.getMe().validate(token);
        }
        return getAttr("user");
    }
    protected GroupMemberinfoModel getUserinfo()
    {
    	GroupMemberModel user = getAttr("user");
        GroupMemberinfoModel userinfo=GroupMemberinfoModel.dao.findFirst(MEMBERINFOMIDSSQL,user.getStr(GroupMemberModel.MID));
        
        return userinfo;
    }
    /**
     * 取图片地址字符串中的第一张图片地址
     * @return
     */
    protected String getImageString(String temp)
    {
    	String t=null;
    	if(temp!=null&&(!temp.equals("null")||!temp.equals("undefined")))
    	{
    		if(temp.indexOf(",")!=-1)
    		{
    			t=temp.split(",")[0];
    		}
    	}
    	return t;
    }
    /**
     * 通过会员手机号码获取会员详细信息返回对象
     * @return
     */
    protected GroupMemberInfoEntey getMemberInfoEntey(String mid,String groupid,int n,String tomid)
    {
    	GroupMemberInfoEntey gmi=new GroupMemberInfoEntey();
    	GroupMemberinfoModel userinfo=GroupMemberinfoModel.dao.findFirst(MEMBERINFOMIDSSQL,tomid!=null?tomid:mid);
    	//查询会员基础数据，修改realname/headimage/msex字段值
    	GroupMemberModel nowUser = GroupMemberModel.dao.findFirst(MEMBERMIDSSQL,tomid!=null?tomid:mid);
    	SystemCollectModel scm = null;
    	 if(userinfo!=null)
    	 {
	    	 gmi.setN0(userinfo.getStr(GroupMemberinfoModel.ID));
//	    	 gmi.setN1(userinfo.getStr(GroupMemberinfoModel.HEADIMAGE));
//	    	 gmi.setN2(userinfo.getStr(GroupMemberinfoModel.REALNAME));
	    	 gmi.setN1(nowUser.getStr(GroupMemberModel.HEADIMAGE));
	    	 gmi.setN2(nowUser.getStr(GroupMemberModel.REALNAME));
	    	 GroupMemberCompanyModel gmcc= GroupMemberCompanyModel.dao.findFirst(MEMBER_COMPAYINGO_SQL, tomid!=null?tomid:mid,groupid);
	    	 gmi.setN3(gmcc!=null?gmcc.getStr(GroupMemberCompanyModel.COMNAME):Code.FINAL_STRING_COMPANY);
	    	 gmi.setN4(userinfo.getStr(GroupMemberinfoModel.MID));
	    	 gmi.setN5(userinfo.getStr(GroupMemberinfoModel.NATIVEPLACE));
//	    	 gmi.setN6(userinfo.getStr(GroupMemberinfoModel.SEX));
	    	 gmi.setN6(nowUser.getStr(GroupMemberModel.SEX));
	    	 gmi.setN7(userinfo.getStr(GroupMemberinfoModel.BIRTHDAY));
	    	 gmi.setN8(n);//消息总数
	    		scm = SystemCollectModel.dao.findFirst(
						SYSTEMCOLLECT_ISCOLL_SQL,
						groupid,
						44444,userinfo.getStr(GroupMemberinfoModel.ID), mid);
	    		gmi.setN9(scm != null ? 0 : 1);
    	 }else
    		 gmi=null;
    	return gmi;
    }
    
    protected  <T> T getRepuestJosnObject(BufferedReader reader,Class<T> objClass) {
    	StringBuffer buffer=null;
    	try {
    		buffer = new StringBuffer();
	        String string;
	        while ((string = reader.readLine()) != null) {
	                    buffer.append(string);
	        }
	        reader.close();  
	         return (T)JsonObjectUtil.json2Bean(buffer.toString(), objClass);
		} catch (IOException e) {
			e.printStackTrace();
		}
    	
		return null;
	}
    
    protected GroupMemberCompanyModel getCompanyinfo()
    {
    	GroupMemberCompanyModel gmcm =new GroupMemberCompanyModel();
    	
    	return gmcm;
    }
    /**
     * 通过会员手机号码获取会员详细信息返回对象
     * @return
     */
    protected GroupMemberInfoEntey getQueryMemberInfoEntey(String mid,String likevalue,String groupid,int n)
    {
    	GroupMemberInfoEntey gmi=new GroupMemberInfoEntey();
    	 GroupMemberinfoModel userinfo=GroupMemberinfoModel.dao.findFirst("SELECT * FROM (SELECT m.ids,m.mheadimage, m.realname,m.nikename,m.mids,m.mnativeplace,m.msex,m.mbirthday,m.orderids from y_group_member s  right JOIN y_group_memberinfo  m  ON m.mids = s.mids where 1=1 AND s.status = 0 AND s.groupids ='"+groupid+"' AND   m.realname like '%"+likevalue+"%') member");
    	//查询会员基础数据，修改realname/headimage/msex字段值
 		 GroupMemberModel nowUser = GroupMemberModel.dao.findFirst("SELECT s.headimage, s.realname,s.msex FROM y_group_member s WHERE 1=1 AND s.groupids ='"+groupid+"' AND   s.realname like '%"+likevalue+"%'");
    	 if(userinfo!=null)
    	 {
	    	 gmi.setN0(userinfo.getStr(GroupMemberinfoModel.ID));
//	    	 gmi.setN1(userinfo.getStr(GroupMemberinfoModel.HEADIMAGE));
//	    	 gmi.setN2(userinfo.getStr(GroupMemberinfoModel.REALNAME));
	    	 gmi.setN1(nowUser.getStr(GroupMemberModel.HEADIMAGE));
	    	 gmi.setN2(nowUser.getStr(GroupMemberModel.REALNAME));
	    	 GroupMemberCompanyModel gmcc=GroupMemberCompanyModel.dao.findFirst(MEMBER_COMPAYINGO_SQL, mid,groupid);
	    	 gmi.setN3(gmcc!=null?gmcc.getStr(GroupMemberCompanyModel.COMNAME):Code.FINAL_STRING_COMPANY);
	    	 gmi.setN4(userinfo.getStr(GroupMemberinfoModel.MID));
	    	 gmi.setN5(userinfo.getStr(GroupMemberinfoModel.NATIVEPLACE));
//	    	 gmi.setN6(userinfo.getStr(GroupMemberinfoModel.SEX));
	    	 gmi.setN6(nowUser.getStr(GroupMemberModel.SEX));
	    	 gmi.setN7(userinfo.getStr(GroupMemberinfoModel.BIRTHDAY));
	    	 gmi.setN8(n);
    	 }else
    		 gmi=null;
    	return gmi;
    }
    protected String getCreateUUId()
    {
    	return RandomUtils.randomCustomUUID();
    }
    /**
     * 响应接口不存在*
     */
    public void render404() {
        renderJson(new BaseResponse(Code.NOT_FOUND));
    }

    /**
     * 响应请求参数有误*
     * @param message 错误信息
     */
    public void renderArgumentError(String message) {

        renderJson(new BaseResponse(Code.ARGUMENT_ERROR, message));

    }

    /**
     * 响应数组类型*
     * @param list 结果集合
     */
    public void renderDataResponse(List<?> list) {
        DataResponse resp = new DataResponse();
        resp.setData(list);
        if (list == null || list.size() == 0) {
            resp.setMessage("未查询到数据");
        } else {
            resp.setMessage("success");
        }
        renderJson(resp);
        
    }

    /**
     * 响应操作成功*
     * @param message 响应信息
     */
    public void renderSuccess(String message) {
        renderJson(new BaseResponse().setMessage(message));
    }

    /**
     * 响应操作失败*
     * @param message 响应信息
     */
    public void renderFailed(String message) {
        renderJson(new BaseResponse(Code.FAIL, message)); 
    }
    /**
     * 判断请求类型是否相同*
     * @param name
     * @return
     */
    protected boolean methodType(String name) {
        return getRequest().getMethod().equalsIgnoreCase(name);
    }
    
    /**
     * 判断参数值是否为空
     * @param rules
     * @return
     */
    public boolean notNull(Require rules) {

        if (rules == null || rules.getLength() < 1) {
            return true;
        }

        for (int i = 0, total = rules.getLength(); i < total; i++) {
            Object key = rules.get(i);
            String message = rules.getMessage(i);
            BaseResponse response = new BaseResponse(Code.ARGUMENT_ERROR);
            
            if (key == null) {
                renderJson(response.setMessage(message));
                return false;
            }

            if (key instanceof String && StringUtils.isEmpty((String) key)) {
                renderJson(response.setMessage(message));
                return false;
            }

            if (key instanceof Array) {
                Object[] arr = (Object[]) key;

                if (arr.length < 1) {
                    renderJson(response.setMessage(message));
                    return false;
                }
            }
        }

        return true;
    }
}
